/**
 * 
 */

package com.wutianyi.thrift.example.threads;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

import com.wutianyi.pool.concurrent.CountTime;
import com.wutianyi.thrift.ThreadsTest;

/**
 * @author wutianyi
 * 
 */
public class ThreadsClient {

	public static void main(String[] args) throws TException, InterruptedException {

//		 TTransport transport = new TSocket("localhost", 9090);
//		 TProtocol protocol = new TBinaryProtocol(transport);
//		 transport.open();
//		
//		 final ThreadsTest.Client client = new ThreadsTest.Client(protocol);
//		 int val = 0;
//		 val = client.threadOne(5);
//		 System.out.println(val);
//		 val = client.stop();
//		 System.out.println(val);
//		 val = client.threadTwo(5);
//		 System.out.println(val);
		CountTime countTime = new CountTime(new Runnable() {

			@Override
			public void run() {
				TTransport transport = null;
				try {
					transport = new TSocket("localhost", 9090, 10000);
					TProtocol protocol = new TBinaryProtocol(transport);
					
					transport.open();
					ThreadsTest.Client client = new ThreadsTest.Client(protocol);
					long start = System.currentTimeMillis();
					int i = client.threadOne(5);
					long end = System.currentTimeMillis();
					System.out.println(Thread.currentThread().getName() + "finish " + i + " time: " + (end - start));
					
				}catch(TException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} finally {
					transport.close();
				}
			}
		}, 4);
		// Thread.sleep(10000);
//		 transport.close();
	}
}
